package recharge

import (
	"context"

	"gitee.com/liuxuezhan/ar-platform/rpc-client/assetsClient/rpc"

	"gitee.com/liuxuezhan/ar-platform/assets-api/internal/svc"
	"gitee.com/liuxuezhan/ar-platform/assets-api/internal/types"

	"github.com/zeromicro/go-zero/core/logx"
)

type RechargeTypeListLogic struct {
	logx.Logger
	ctx    context.Context
	svcCtx *svc.ServiceContext
}

// 用户充值页面--充值类型--列表
func NewRechargeTypeListLogic(ctx context.Context, svcCtx *svc.ServiceContext) *RechargeTypeListLogic {
	return &RechargeTypeListLogic{
		Logger: logx.WithContext(ctx),
		ctx:    ctx,
		svcCtx: svcCtx,
	}
}

func (l *RechargeTypeListLogic) RechargeTypeList(req *types.RechargeTypeListRequest) (*types.RechargeTypeListResponse, error) {

	in := rpc.RechargeTypeListRequest{}
	list, err := l.svcCtx.AssetsRpc.PayRecharge.RechargeTypeList(l.ctx, &in)
	if err != nil {
		return nil, err
	}

	if len(list.Records) == 0 {
		return nil, err
	}

	records := make([]types.RechargeTypeListResponse_Data, len(list.Records))
	for i, record := range list.Records {
		records[i] = types.RechargeTypeListResponse_Data{
			Id:             record.Id,
			Name:           record.Name,
			SelectedIcon:   record.SelectedIcon,
			UnselectedIcon: record.UnselectedIcon,
			ViewType:       record.ViewType,
			IsCopyIcon:     record.IsCopyIcon,
		}
	}

	return &types.RechargeTypeListResponse{
		Data: records,
	}, nil
}
